package com.example.sys.Controller;

import com.example.sys.Enity.StudentInfo;
import com.example.sys.Mapper.StudentInfoMapper;
import com.example.sys.Service.StudentInfoService;
import com.example.sys.vo.StudentInfoClassInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@CrossOrigin
@RestController
@RequestMapping("stu")
public class StudentInfoController {

    @Autowired
    private StudentInfoService studentInfoService;

    //http://localhost:8080/stu/query get name
    @GetMapping("/query")
    public List<StudentInfo> queryStudentInfoByName( String name) {
        return studentInfoService.getAllStudentInfo(name);
    }

    //http://localhost:8080/stu/querystu get name
    @GetMapping("querystu")
    public List<StudentInfoClassInfo> queryStudentInfoAndClassInfoByName(@RequestParam String name, @RequestParam Integer clsid) {
        List<StudentInfoClassInfo> stuClass =null;
        if (clsid == 0) {
            stuClass = studentInfoService.getAllStuAndClassByName(name);
        }else{
             stuClass = studentInfoService.getAllStuAndClassByclsAndName(name,clsid);
        }

            return stuClass;
        }
        //http://losthost:8080/stu/del/197 get name
        @GetMapping("del/{id}")
        private Integer delStudentInfo (@PathVariable Integer id){
            return studentInfoService.deleteByID(id);
        }
        @PostMapping("add")
    public Integer addStudentInfo(@RequestBody StudentInfo studentInfo){
        Integer i = studentInfoService.insertStudentInfo(studentInfo);
                return i;
        }
    }
